package com.project.forlearning.controller;

import com.project.forlearning.service.BackUserResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户收藏API
 */
@Api(value = "UserResourceController",tags = {"后台用户收藏相关API"})
@RestController
@RequestMapping("userResources")
@CrossOrigin
public class BackUserResourceController {

    @Autowired
    private BackUserResourceService userResourceService;

    @ApiOperation("查询某一个用户的某一个收藏资源,需传入资源编号resourceId和用户id, 即userId")
    @GetMapping("{resourceId}/{userId}")
    public String getUserResource(@ApiParam(value = "资源编号", required = true) @PathVariable int resourceId,
                                  @ApiParam(value = "用户编号", required = true) @PathVariable int userId){
        return userResourceService.findUserResource(resourceId,userId);
    }

    @ApiOperation("查询某一个用户的所有收藏资源，需传入用户id")
    @GetMapping("{userId}")
    public String getUserAllResource(@ApiParam(value = "用户编号", required = true) @PathVariable int userId){
        return userResourceService.findUserAllResource(userId);
    }

    @ApiOperation("删除某一个用户的某一个收藏资源，需传入资源编号和用户id")
    @DeleteMapping("{resourceId}/{userId}")
    public String deleteUserResource(@ApiParam(value = "资源编号", required = true) @PathVariable int resourceId,
                                     @ApiParam(value = "用户编号", required = true) @PathVariable int userId){
       return userResourceService.deleteUserResource(resourceId,userId);
    }
}
